import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import './assets/all.css'
import http from './tool/http'
import echarts from 'echarts'
import log from './tool/rizhi'
Vue.config.productionTip = false
Vue.prototype.$axios = http
Vue.prototype.$echarts = echarts
Vue.use(ElementUI);
Vue.prototype.log = log
router.beforeEach((to, from, next)=>{
  if(to.meta.require){
    if(store.state.login.user.name){
      let type = parseInt(store.state.login.user.type)
      // console.log(type)
      if(to.meta.roles.includes(type)){
        next()
      }else {
        sessionStorage.clear()
        alert('没有权限')
        router.push('/login')
      }
    }else{
      alert('请先登录')
      router.push('/login')
    }
  }else {
    next()
  }
})


new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
